package cn.humaohua.study.hadoop.cmdrunner.c2.ncdc;

import cn.humaohua.study.hadoop.cmdrunner.Test;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.springframework.stereotype.Component;

/**
 * hadoop fs -rm -R /user/hmh/output/ncdc
 *
 * hadoop fs -cat /user/hmh/output/ncdc/part-r-00000
 */
@Component
public class MaxTemperature implements Test {
    public static final String INPUT_PATH="hdfs://localhost:8020/user/hmh/input/ncdc/sample.txt";
    public static final String OUTPUT_PATH="hdfs://localhost:8020/user/hmh/output/ncdc";

    @Override
    public void test() throws Exception {
        Job job = Job.getInstance();
        job.setJarByClass(MaxTemperature.class);
        job.setJobName("Max temperature");

        FileInputFormat.addInputPath(job, new Path(INPUT_PATH));
        FileOutputFormat.setOutputPath(job, new Path(OUTPUT_PATH));

        job.setMapperClass(MaxTemperatureMapper.class);
        job.setReducerClass(MaxTemperatureReducer.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);

        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }

}
